<?php

// 
// this simply reads the headers for a given long DMid and returns the short DMid
// transparently passes short ids and returns null (in a JS object) if the page pulls a 404
// if the page isn't found, DMid is an empty string
// 

# set up timer variables
$time = explode(" ", microtime()); 
$stime = $time[1] . substr($time[0],1,strlen($time[0])); 

$headers = get_headers('http://www.dailymotion.com/swf/' . htmlspecialchars($_GET['DMid']), 1);

parse_str($headers['Location'], $DMlocation);
preg_match('%video/([^_]+)_%', $DMlocation['selfURL'], $url);

$time2 = explode (" ",microtime ()); 
$etime = $time2[1] . substr($time2[0],1,strlen($time2 [0])); 

echo htmlspecialchars($_GET['_callback']) . '({"DMid":"' . $url[1] . '", "execution_time":' . round($etime - $stime,4) . ' })';
?>